package com.platform.manager.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 * User: wangyanginfo
 * Date: 12-8-28
 * Time: 下午2:48
 * To change this template use File | Settings | File Templates.
 */
@Aspect
@Service("aopByAspect")
public class AopByAspect {

    @Pointcut("execution (* com.platform.manager.*.*(..))")
    public void point() {
    }

    @Before("point()")
    public void beforePoint(JoinPoint joinpoint) {
        System.out.println("POINT - 切入点 方法前执行" + joinpoint.getArgs().length);
        System.out.println("POINT - 切入点 方法前执行" + joinpoint.getTarget());
        System.out.println("POINT - 切入点 方法前执行" + joinpoint.getSignature().getName());
    }

    @AfterReturning(pointcut="point()", returning="returnValue")
    public void afterPoint(JoinPoint joinpoint, Object returnValue) {
        System.out.println("POINT - 切入点 方法后执行" + joinpoint.getArgs().length);
        System.out.println("POINT - 切入点 方法后执行" + joinpoint.getTarget());
        System.out.println("POINT - 切入点 方法后执行" + joinpoint.getSignature().getName());
        System.out.println("POINT - 切入点 方法后执行" + returnValue.getClass().getName());
    }

    @Around("point()")
    public Object interceptorPoint(ProceedingJoinPoint proceedingJoinPoint) throws Throwable{
        System.out.println("POINT - 切入点 环绕方法前执行" + proceedingJoinPoint.getArgs().length);
        Object retVal = proceedingJoinPoint.proceed();
        System.out.println("POINT - 切入点 环绕方法后执行" + retVal.getClass().getName());
        return retVal;
    }

    @AfterThrowing(pointcut="point()", throwing="ex")
    public void afterThrowing(Exception ex) {
        System.out.println("切入点异常处理通知afterThrowing(Method method, Object[] args, Object target,Throwable throwable)");
    }
}
